package com.xuanxu.blogs.framework.mybatisplus.core.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.xuanxu.blogs.framework.common.enums.StatusEnum;
import org.apache.ibatis.reflection.MetaObject;

import java.time.LocalDateTime;

/**
 *  数据自动填充元数据处理器
 * @author XuanXu
 * @version 1.0
 * @date 2024-08-18 22:05
 */
public class DataAutoFillMetaObjectHandler implements MetaObjectHandler {
    @Override
    public void insertFill(MetaObject metaObject) {
        // TODO 用户ID
        this.strictInsertFill(metaObject, "createTime", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
        this.strictInsertFill(metaObject, "isDelete", Integer.class, StatusEnum.FALSE.getStatus());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        // TODO 用户ID
        this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
    }
}
